﻿<?php
require_once('common.php');
echo "<h2>file_get_contents获取本地文件内容</h2>";
/*file_get_contents打开本地文件*/
$filename = "test.html";
$fc = file_get_contents($filename);
echo "<h3>本地文件内容：</h3>" . $fc;

/*fopen打开远程url  get方法*/
echo "<h2>file_get_contents获取远程url文件内容 get方法</h2>";
$filename = getHost() . "spiders/test.php?info=你好";
$fc = file_get_contents($filename);
echo "<h3>输出http_response_header</h3>";
dumpout($http_response_header);
echo "<h3>get方法获取远程url内容：</h3>".$fc;

/*fopen打开远程url  post方法*/
echo "<h2>file_get_contents获取远程url文件内容 post方法</h2>";
$filename = getHost() . "spiders/test.php";
$post = array('info' => '你好');
$content = http_build_query($post);
$content_length = strlen($content);
$options = array(
    'http' => array(
        'method' => 'POST',
        'header' =>
            "Content-type: application/x-www-form-urlencoded\r\n" .
            "Content-length: $content_length\r\n",
        'content' => $content
    )
);
$fc = file_get_contents($filename, false, stream_context_create($options));
echo "<h3>输出http_response_header</h3>";
dumpout($http_response_header);
echo "<h3>post方法获取远程url内容：" . $fc . "</h3>";


?>
